package com.qiwx.pigeon.presenter;

import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.FarmPageParam;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.data.vo.stock.AddGoodBean;
import com.qiwx.pigeon.data.vo.stock.CustomerBean;
import com.qiwx.pigeon.data.vo.stock.GoodCategory;
import com.qiwx.pigeon.viewinterface.ICommonView;

import java.lang.ref.WeakReference;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @description
 * @Author qiwx
 * @Date 2020-04-26 09:59
 * 商品类别
 **/
public class GoodCatePresenter extends BasePresenter<ICommonView<GoodCategory>> {

    public GoodCatePresenter(WeakReference<ICommonView<GoodCategory>> from) {
        super(from);
    }

    public GoodCatePresenter(ICommonView from) {
        super(from);
    }

    // 商品类别
    public void addGoodCategory(GoodCategory params) {
        ApiManager.getApiServer().addGoodCategory(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onAddSuccess(response);

                    }
                });
    }
    // 添加商品
    public void addGood(AddGoodBean params) {
        ApiManager.getApiServer().addGoodRecord(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onAddSuccess(response);

                    }
                });
    }


    //获取商品列表
    public void getGoodCateListByPage(FarmPageParam params) {
        ApiManager.getApiServer().getGoodCateListByPage(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<PageInfo<GoodCategory>>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<PageInfo<GoodCategory>> response) {
                        getView().onQueryListSuccess(response.data);
                    }

                });
    }

    //删除商品分类
    public void deleteGoodCate(GoodCategory params) {
        ApiManager.getApiServer().deleteGoodCate(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onDeleteSuccess(response);

                    }
                });
    }

}
